//数据库表名
const String tableName = 'books';
//排序方式
const String orderType = 'desc';
//排序字段
const String orderColumn = BookFields.create_time;

///数据表字段
class BookFields {
  ///字段名
  static final List<String> values = [
    book_id,
    is_checked,
    book_num,
    book_name,
    book_desc,
    create_time
  ];

  static const String book_id = 'book_id';
  static const String is_checked = 'is_checked';
  static const String book_num = 'book_num';
  static const String book_name = 'book_name';
  static const String book_desc = 'book_desc';
  static const String create_time = 'create_time';
}

class Books {
  final int? bookId;
  final bool isChecked;
  final int bookNum;
  final String bookName;
  final String bookDesc;
  final DateTime createTime;

  const Books({
    this.bookId,
    required this.isChecked,
    required this.bookNum,
    required this.bookName,
    required this.bookDesc,
    required this.createTime,
  });

  Books copy({
    int? bookId,
    bool? isChecked,
    int? bookNum,
    String? bookName,
    String? bookDesc,
    DateTime? createTime,
  }) =>
      Books(
        bookId: bookId ?? this.bookId,
        isChecked: isChecked ?? this.isChecked,
        bookNum: bookNum ?? this.bookNum,
        bookName: bookName ?? this.bookName,
        bookDesc: bookDesc ?? this.bookDesc,
        createTime: createTime ?? this.createTime,
      );

  static Books fromJson(Map<String, Object?> json) => Books(
        bookId: json[BookFields.book_id] as int?,
        isChecked: json[BookFields.is_checked] == 1,
        bookNum: json[BookFields.book_num] as int,
        bookName: json[BookFields.book_name] as String,
        bookDesc: json[BookFields.book_desc] as String,
        createTime: DateTime.parse(json[BookFields.create_time] as String),
      );

  Map<String, Object?> toJson() => {
        BookFields.book_id: bookId,
        BookFields.book_name: bookName,
        BookFields.is_checked: isChecked ? 1 : 0,
        BookFields.book_num: bookNum,
        BookFields.book_desc: bookDesc,
        BookFields.create_time: createTime.toIso8601String(),
      };
}
